package com.smasher.widget.edit;

import android.text.InputFilter;
import android.widget.EditText;
import android.widget.TextView;

public class EditTextHelper {

    /**
     * 让一个输入框只能输入指定位数小数 和整数位
     *
     * @param editText     EditText
     * @param inputFilters InputFilters
     */
    public static void setCashierInputFilter(final EditText editText, InputFilter... inputFilters) {
        if (inputFilters == null || inputFilters.length == 0) {
            editText.setFilters(new InputFilter[]{new CashierInputFilter()});
        } else {
            InputFilter[] newInputFilters = new InputFilter[inputFilters.length + 1];
            System.arraycopy(inputFilters, 0, newInputFilters, 0, inputFilters.length);
            newInputFilters[inputFilters.length] = new CashierInputFilter();
            editText.setFilters(newInputFilters);
        }

    }


    /**
     * 获取文本框内容
     *
     * @param textView textView
     * @return
     */
    public static String getEditContent(TextView textView) {
        if (textView == null) {
            return null;
        }
        CharSequence charSequence = textView.getText();
        if (charSequence != null) {
            return charSequence.toString();
        }
        return null;
    }
}
